package testing;

import org.junit.Test;

import common.messages.KVMessage;
import communicationLogic.ClientSocket;
import app_kvClient.KVClient;
import client.KVStore;
import junit.framework.TestCase;

public class AdditionalTest extends TestCase {

    // TODO add your test cases, at least 3

    private KVClient client;
    private KVStore kvClient;
    private ClientSocket cs;
    Exception ex = null;
    KVMessage response = null;

    public void setUp() {
        kvClient = new KVStore("localhost", 50000);
        try {
            kvClient.connect();
        } catch (Exception e) {
        }
    }

    public void tearDown() {
        kvClient.disconnect();
    }

    @Test
    public void testSetLogLevel() {
        client = new KVClient();
        try {
            client.setLevel("asdf");
        } catch (Exception e) {
            ex = e;
        }
        assertNull(ex);
    }

    @Test
    public void testPutLongkey() {
        String key = "foooooooooooooooooooooooooooooo";
        String value = "bar";
        try {
            response = kvClient.put(key, value);
        } catch (Exception e) {
            ex = e;
        }
        assertTrue(ex == null && response != null);
    }

    @Test
    public void testReDisconnect() {
        try {
            cs = new ClientSocket("localhost", 50000);
            cs.connect();
            cs.disConnect();
            cs.disConnect();
        } catch (Exception e) {
            ex = e;
        }
        assertNull(ex);
    }
}
